<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>商品出货单  - 仓库管理</title>
    <script type='text/javascript' src="<%=basePath %>/jquery/jquery-1.4.2.js"></script>
	<script type="text/javascript" src="<%=basePath%>/comm/js/map.js"></script>
	
	<link href="<%=basePath %>/background/css/layout.css" rel="stylesheet" type="text/css" />
    <link href="<%=basePath %>/background/css/header.css" rel="stylesheet" type="text/css" />
    <link href="<%=basePath %>/warehouse/css/button.css" rel="stylesheet" type="text/css" />
    
  </head>


  <body>
  
  
  <div id="container">
  <div id="header">
		 <jsp:include page="/background/head.jsp"></jsp:include>
	</div>
  <div id="applicationbar">
		 <jsp:include page="/background/app/appbar.jsp"></jsp:include>
	</div>
  <div id="mainContent">
    <div id="sidebar">

		<jsp:include page="/background/left.jsp"></jsp:include>
	</div>
	
	
	
    <div id="content" >
    <div style="border:1px solid #ffffff; border-top-color:#6cb1f1; background-color: #e5f3ff; width: 100%; top: 0px;" >
							<a href="<%=basePath %>warehouse/managereceiptlist_warehouse.action">出仓管理</a>  - 商品出货单
     			<input class="small button orange" style="bottom: 1px;" type="button" value="查看谁有权限" 
     				onclick="javascript:openUrlForDialog('selectoperatorlimitedAction_background.action?limitedCode=<s:property value="limitedcode"/>')"/>
	</div>
	
	
    
   <form action="warehouse/addreceiptlist_warehouse.action" method="post" accept-charset="UTF-8" id="addreceiptlist_warehouseForm" name="addreceiptlist_warehouseForm"> 
				<s:token />
     <table border="0" cellpadding="0" cellspacing="0"   style= "border:1px solid #ffffff; padding: 5px;width: 100%;">
    	 <tr>
     		<td width="100%">
     
     	</td>
     		</tr>
 		<tr>
     		<td>
     			<FONT color="red"><s:property value="operationResult"/></FONT>
     			<s:fielderror id="errormessage" />
     			<br/>
     			
				<table  style= "border:1px solid #ffffff; padding: 5px;" class="bottomline">
					<tr>
					
						<td width="100">部门:</td>
						<td >
						
						
						<select id="department_receiptlist" name="department_receiptlist">
							<option value="1|易宜拍拍">易宜拍拍</option>
							<option value="2|凌趣淘宝">凌趣淘宝</option>
							<option value="3|易宜淘宝">易宜淘宝</option>
							<option value="4|同行">同行</option>
							<option value="5|自取">自取</option>
						</select>
						<input type="hidden" id="departmentid_receiptlist" name="departmentid_receiptlist">
						</td>
						<td >
						
						</td>
						<td></td>
					</tr>
					
					<tr  >
					
						<td>客户ID:</td>
						<td>
						
						<input class="searchtxt" type="text" id="customerid_receiptlist" name="customerid_receiptlist" size="40" maxlength="32" onblur="javascript:enterCustomerid();" autofocus="autofocus" required="required"/>
						
					
						</td>
						<td id="lastsalescustomerdateDisplay" align="left">
							
						</td>
						<td></td>
					</tr>
					
					<tr style="margin: 5px">
					
						<td width="100">客户信息:</td>
						<td >
						
						
						<textarea style="


 

border: 1px solid #9DADC5;
border-radius: 3px;
color: #494949;
font-size: 20px;
height: 90px;

outline: medium none currentColor; 

position: relative; 
width: 400px;
background-color:#ffffff;" id="customerinfo_receiptlist" name="customerinfo_receiptlist" rows="3" cols="33" ></textarea>
						
						</td>
						<td >
						
						</td>
						<td></td>
					</tr>
					
					<tr>	
					<td>
								  仓库:
								   
							  </td>
				  			<td >
				  				<select id="warehouseid_receiptlist" name="warehouseid_receiptlist" disabled="disabled">
				  					<s:iterator value="warehouseList" id="warehouseList">
				  						<option value="<s:property value="#warehouseList.id_warehouse"/>"><s:property value="#warehouseList.name_warehouse"/></option>	
				  					</s:iterator>
				  					
								  </select>
				  			</td>
				  			<td >
						
						</td>
						<td></td>
						
				  		</tr>
				</table>
				

	</td>
     		</tr>
     		
     		<tr>
				<td>
					<table id="receiptListTable"  width="100%" border="0"   cellpadding="2"  bordercolor="#6cb1f1" cellspacing="0" style= "border:1px solid #ffffff;border-top-color:#6cb1f1;border-bottom-color:#6cb1f1;">
								<thead>
								<tr bgcolor="#e5f3ff">
									<td width="100">
										仓库
									</td>
									<td width="110">
									     商品ID
									</td>
									<td width="305">
										商品名称
									</td>
									
									<td width="105">
										数量(单位)
									</td>
								
									<td width="60">
										单价
									</td>
									
									<td width="120">
										全额
									</td>
									
									
									<td>
										备注
									</td>
									
									<td width="80">
										操作
									</td>
								</tr>
								</thead>
								<tbody>
								</tbody>
								
							</table>
				</td>
     		</tr>
     		 <tr>
     		<td>
     			<table>
     				<tr>
     					<td>
     						<input class="mtxt" type="text" size="20" id="searchStr" name="searchStr" />
     						<input class="large button blue" style="bottom:5px;"  value="添加产品" type="button" onclick="javascript:openUrlForDialog('insertreceiptinfo_warehouse.action?searchStr='+$('#searchStr').attr('value'));"/>
     					</td>
     				</tr>
     			</table>
     		</td>
     		</tr>
     		 <tr>
     		<td width="100%">
     		
     		
     			<table style="width: 100%;border: 1px ; border-color: #000000;">
     			
     			<tr>
					
						<td width="80">运费:</td>
						<td>
							<input class="mtxt"  id="shipprice_receiptlist" name="shipprice_receiptlist" onchange="enterShip()"/>
						</td>
						<td>产品数量:</td> 
						<td id="goodsnumber">0</td>
						
						<td >总额:</td>
						<td  width="300" id="totalDisply">0</td> 
					</tr>
					
					
					<tr>
						<td>快递单号:</td>
						<td>
							<input class="searchtxt" type="text" id="shipno_receiptlist" name="shipno_receiptlist" maxlength="128"/>
						</td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
					</tr>
					
					<tr>
						<td>描述/备注:</td>
						<td>
						<input type="hidden" id="shipprice_receiptlist" name="shipprice_receiptlist" value="0.00"/>
						<input type="hidden" id="goodsnumber_receiptlist" name="goodsnumber_receiptlist" value="0"/>
						<input type="hidden" id="total_receiptlist" name="total_receiptlist" value="0"/>
						<input type="hidden" id="receiptInfo" name="receiptInfo" value=""/>
						
						<textarea rows="2" cols="34"  id="remark_receiptlist" name="remark_receiptlist"></textarea>
						
						
						</td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
					</tr>
					

				</table>
		
     	</td>
     	</tr> 
     		
     	<tr height="50">
     		<td > 
     			<button class="large button yellow" type="button" onclick="submitReceiptlist()">添加</button>
		
     		</td>
     	</tr>
     	
     	
     	
     	</table>
     	</form>

	
	</div>
  </div>
  <div id="footer">
<jsp:include page="/background/tail.jsp"></jsp:include>
	</div>
</div>

  
  
  
  
  </body>
  <script type="text/javascript">

  var number = 0;
  var total = 0.00;
  var shipprice = 0;
  var receiptMap = new Map();
  var mapId = 0;
  var goodsreserve = 0;
  function submitReceiptlist(){
	  enterShip();
	  addreceiptlist_warehouseForm['shipprice_receiptlist'].value = shipprice;
	  addreceiptlist_warehouseForm['goodsnumber_receiptlist'].value = number;
	  addreceiptlist_warehouseForm['total_receiptlist'].value = total;

	 var customerid = addreceiptlist_warehouseForm['customerid_receiptlist'].value;

	 if(customerid == ""){
		 alert("客户ID不能为空!");
		 return ;

	}//*/

	  if(receiptMap.elements.length<1){
			alert("请选择需要出货的商品, :) ");
			return ;
		}


		
	 var receiptInfoValue = "";

	 /*
	  var arr = receiptMap.elements;
		//alert(receiptMap.elements.length);
		for(i=0;i<receiptMap.elements.length;i++){
			receiptInfoValue += receiptMap.elements[i].value +"|";
			//alert(receiptMap.elements[i].value);
		}
	  addreceiptlist_warehouseForm['receiptInfo'].value = receiptInfoValue;
	  alert(addreceiptlist_warehouseForm['receiptInfo'].value);

	  */
	  
	  receiptInfoValue = ( $("#receiptListTable input").map(function(){
		  return $(this).val();
		}).get().join(",") );
		
	  addreceiptlist_warehouseForm['receiptInfo'].value = receiptInfoValue;
	 // alert(addreceiptlist_warehouseForm['receiptInfo'].value);
	 // return ;
	  
	  addreceiptlist_warehouseForm.submit();
  }






  
  
  function insertGoodsForTable(goodsinfo){
	  
		//alert(goodsinfo);
		var goodsinfovalue = goodsinfo;
		if(goodsinfo != undefined){
			//addpurchase_warehouseForm["goodsinfo"].value=goodsinfo;
			
			var index = goodsinfo.indexOf(",");
			var warehouseid = goodsinfo.substring(0,index);

			goodsinfo = goodsinfo.substring(index+1,goodsinfo.length);
			index = goodsinfo.indexOf(",");
			var warehousename = goodsinfo.substring(0,index);
			
			goodsinfo = goodsinfo.substring(index+1,goodsinfo.length);
			index = goodsinfo.indexOf(",");
			var goodsid = goodsinfo.substring(0,index);

			goodsinfo = goodsinfo.substring(index+1,goodsinfo.length);
			index = goodsinfo.indexOf(",");
			var goodsname = goodsinfo.substring(0,index);


			goodsinfo = goodsinfo.substring(index+1,goodsinfo.length);
			index = goodsinfo.indexOf(",");
			var goodsnumber = new Number(goodsinfo.substring(0,index));

			goodsinfo = goodsinfo.substring(index+1,goodsinfo.length);
			index = goodsinfo.indexOf(",");
			var goodsunit = goodsinfo.substring(0,index);

			goodsinfo = goodsinfo.substring(index+1,goodsinfo.length);
			index = goodsinfo.indexOf(",");
			var goodsprice = new Number(goodsinfo.substring(0,index));

			goodsinfo = goodsinfo.substring(index+1,goodsinfo.length);
			index = goodsinfo.indexOf(",");
			var remark = goodsinfo.substring(index,goodsinfo.length);

			

			var count = goodsprice * goodsnumber;
			
			


			
			number += goodsnumber;
			total += count;
			
			shipprice = new Number(document.getElementById("shipprice_receiptlist").value);
			//alert(shipprice);
			document.getElementById("goodsnumber").innerHTML = number;
			document.getElementById("totalDisply").innerHTML = (total+shipprice) + " <font color='red'>(包含邮费:" + shipprice + ")<font>";
			
			//alert(warehouseid + ","+goodsid+","+goodsnumber);
			addRow(warehouseid,warehousename,goodsid,goodsname,goodsnumber,goodsunit,goodsprice,count,remark,goodsinfovalue);
			
			
		}
		
		// opener.
		 
	};


	function deleteRow(r,goodsnumber,count,id)   
	{   
		var i=r.parentNode.parentNode.rowIndex;
		document.getElementById('receiptListTable').deleteRow(i);
		number -= goodsnumber;
		total -= count;
		
		shipprice = new Number(document.getElementById("shipprice_receiptlist").value);
		//alert(shipprice);
		document.getElementById("goodsnumber").innerHTML = number;
		document.getElementById("totalDisply").innerHTML = (total+shipprice) + " <font color='red'>(包含邮费:" + shipprice + ")<font>";
		receiptMap.remove(id);
		changeTotalInfo();
	}   
	  
	function insertRowInTable(warehouseid,warehousename,goodsid,goodsname,goodsnumber,goodsunit,goodsprice,count,remark,goodsinfovalue){   
		var table = document.getElementById("receiptListTable");   
		var newRow = table.insertRow(-1);   
		var i=newRow.rowIndex;
		mapId++;
		//alert(i);
		newRow.insertCell().innerHTML = warehousename 
		 + "<input id='tWarehouseId"+mapId+"' name='tWarehouseId"+mapId+"'  type='hidden' value='"+ warehouseid +"'/>" 
		 + "<input id='tWarehouseName"+mapId+"' name='tWarehouseName"+mapId+"'  type='hidden' value='"+ warehousename +"'/>"; 
		//newRow.insertCell().innerHTML = trcode;   
		newRow.insertCell().innerHTML = goodsid
		+ "<input id='tGoodsId"+mapId+"' name='tGoodsId"+mapId+"'  type='hidden' value='"+ goodsid +"'/>"; 
		 
		newRow.insertCell().innerHTML = "<a href=\"#\">"+goodsname + "</a>" 
		+ "<input id='tGoodsName"+mapId+"' name='tGoodsName"+mapId+"'  type='hidden' value='"+ goodsname +"'/>"
		+ "<input id='tGoodsUnit"+mapId+"' name='tGoodsUnit"+mapId+"'  type='hidden' value='"+ goodsunit +"'/>";
		

		
		newRow.insertCell().innerHTML = "<input id='tGoodsNumber"+mapId+"' name='tGoodsNumber"+mapId+"' onblur='changeGoodsInfo("+mapId+")' size='4' type='text' value='"+ goodsnumber +"'/>(" + goodsunit + ")";
			
		
		newRow.insertCell().innerHTML = "<input id='tGoodsPrice"+mapId+"' name='tGoodsPrice"+mapId+"' onblur='changeGoodsInfo("+mapId+")' size='6' type='text' value='"+ goodsprice +"'/>";
		newRow.insertCell().innerHTML = "<div id='tCount"+mapId+"' name='tCount"+mapId+"'>"+count+"</div>";
		
		newRow.insertCell().innerHTML = remark 
		+ "<input id='tRemark"+mapId+"' name='tRemark"+mapId+"'  type='hidden' value='"+ remark +"'/>";
		
		//alert("mapId"+mapId);
		newRow.insertCell(-1).innerHTML = "<input type='button' class='large button red' value='删除' onclick='deleteRow(this,"+goodsnumber+","+count+","+mapId+")'>"; 
		receiptMap.put(mapId,goodsinfovalue);
		checkGoodsReserve(warehouseid,goodsid,goodsnumber,goodsprice,mapId);

		
		
	}   

	//客户端动态添加行
  	function addRow(warehouseid,warehousename,goodsid,goodsname,goodsnumber,goodsunit,goodsprice,count,remark,goodsinfovalue){   
  	

		var htmlStr  = "";
		mapId++;
		//alert(i);
		htmlStr = htmlStr + "<td>"+ warehousename 
		 + "<input id='tWarehouseId"+mapId+"' name='tWarehouseId"+mapId+"'  type='hidden' value='"+ warehouseid +"'/>" 
		 + "<input id='tWarehouseName"+mapId+"' name='tWarehouseName"+mapId+"'  type='hidden' value='"+ warehousename +"'/>"+ "</d>";  
		//newRow.insertCell().innerHTML = trcode;   
		htmlStr = htmlStr + "<td>"+ goodsid
		+ "<input id='tGoodsId"+mapId+"' name='tGoodsId"+mapId+"'  type='hidden' value='"+ goodsid +"'/>"+ "</d>"; 
		 
		htmlStr = htmlStr + "<td>"+ "<a href=\"#\">"+goodsname + "</a>" 
		+ "<input id='tGoodsName"+mapId+"' name='tGoodsName"+mapId+"'  type='hidden' value='"+ goodsname +"'/>"+ "</d>"; 
		
		

		
		htmlStr = htmlStr + "<td>"+ "<input id='tGoodsNumber"+mapId+"' name='tGoodsNumber"+mapId+"' onblur='changeGoodsInfo("+mapId+")' size='4' type='text' value='"+ goodsnumber +"'/>(" + goodsunit + ")"
		+ "<input id='tGoodsUnit"+mapId+"' name='tGoodsUnit"+mapId+"'  type='hidden' value='"+ goodsunit +"'/>"+ "</d>"; 
		
			
		
		htmlStr = htmlStr + "<td>"+ "<input id='tGoodsPrice"+mapId+"' name='tGoodsPrice"+mapId+"' onblur='changeGoodsInfo("+mapId+")' size='6' type='text' value='"+ goodsprice +"'/>"+ "</d>"; 
		htmlStr = htmlStr + "<td>"+ "<div id='tCount"+mapId+"' name='tCount"+mapId+"'>"+count+"</div>"+ "</d>"+ "</d>";  
		
		htmlStr = htmlStr + "<td>"+ remark 
		+ "<input id='tRemark"+mapId+"' name='tRemark"+mapId+"'  type='hidden' value='"+ remark +"'/>"+ "</d>"; 
		
		
		htmlStr = htmlStr +"<td>"+ "<input id='tSplit"+mapId+"' name='tSplit"+mapId+"'  type='hidden' value='|'/>"
		+ "<a href='javascript:deleteRow(this,"+goodsnumber+","+count+","+mapId+");' class='large button red' onclick='deleteRow(this,"+goodsnumber+","+count+","+mapId+")'>删除</a>"+ "</d>"+ "</d>";  

		htmlStr = "<tr>"+ htmlStr + "</tr>";
		receiptMap.put(mapId,goodsinfovalue);
		checkGoodsReserve(warehouseid,goodsid,goodsnumber,goodsprice,mapId);
  	   

		var tb = $("#receiptListTable>tbody");
        tb.append(htmlStr);
	
		
  	  //  $(htmlStr).insertAfter($("#receiptListTable tbody tr:eq("+rownum+")"));   
  	}


	

	function enterShip(){

		
		shipprice=document.getElementById("shipprice_receiptlist").value;
		if(isNaN(shipprice)){
			//alert("adsf");
			shipprice = 0 ;
			document.getElementById("shipprice_receiptlist").value=0;
		}
		/*alert(shipprice);
		if(isNaN(shipprice)){
			shipprice = new Number(0.0);
		}//*/
		changeTotalInfo();
		
	}

	
	function createXmlHttp() {
  	    //根据window.XMLHttpRequest对象是否存在使用不同的创建方式
  	    if (window.XMLHttpRequest) {
  	       xmlHttp = new XMLHttpRequest();                                     //FireFox、Opera等浏览器支持的创建方式
  	    } else {
  	       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   //IE浏览器支持的创建方式
  	    }
  	  
  	    return xmlHttp;
  	}
  	
	function checkGoodsReserve(warehouseid,goodsid,number,price,mapid){
  		
		$.getJSON("getreceiptinfo_warehouse.action?warehouseid="+warehouseid+"&goodsid=" + goodsid+"&number="+number+"&price="+price, function(data){ 
  			if(data.responseText != ""){
  				alert(data.responseText);
  	  		}
  			document.getElementById("tCount"+mapid).innerHTML=number * price 

  			+ "<font color='#cccccc'>("+data.profit+")</font>";
	
  			
  		});
  		
		
  	}

  
  	

  
  	
	function getLastSalesDateByCustomerid(customerid){
  		
  		xmlhttp = null;    
  		xmlhttp = createXmlHttp();
  		url = encodeURI(encodeURI("getlastsalesdatebycustomerid_warehouse.action?customerid="+customerid));
  		//alert(url);
  		xmlhttp.open("POST", url, true);
  		xmlhttp.onreadystatechange = doGetLastSalesDateByCustomerid;    
  		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");    
  		xmlhttp.send(null);	
  		
  	}

	function doGetLastSalesDateByCustomerid(){
  		
		if (xmlhttp.readyState == 4) {  
		      if (xmlhttp.status == 200) {    
		       //	var saerchResult = "{\"options\":\"" + xmlhttp.responseText +"\"}" ;    
		       var lastSalesDate =  xmlhttp.responseText;
		       if(lastSalesDate!=""){
					//alert(lastSalesDate);
					document.getElementById('lastsalescustomerdateDisplay').innerHTML = 
					"<font color='green'>" + 
						lastSalesDate + "</font>";
					
					return;
	  		     }
		       //alert(xmlhttp.responseText);
		       //alert(replyResult);
		     //document.getElementById('warehousedisply').innerHTML = replyResult;
		      }    
		   }
  		
  	}
	
  	function changeGoodsInfo(mapId){
  	
  		var tWarehouseId = document.getElementById("tWarehouseId"+mapId).value; 
  		
  		var tWarehouseName = document.getElementById("tWarehouseName"+mapId).value; 
  		
  		var tGoodsId = document.getElementById("tGoodsId"+mapId).value;
  		var tGoodsName = document.getElementById("tGoodsName"+mapId).value;
  		var tGoodsNumber = document.getElementById("tGoodsNumber"+mapId).value;
  		var tGoodsUnit = document.getElementById("tGoodsUnit"+mapId).value;
  		var tGoodsPrice = document.getElementById("tGoodsPrice"+mapId).value;
  		var tRemark = document.getElementById("tRemark"+mapId).value;

  		checkGoodsReserve(tWarehouseId,tGoodsId,tGoodsNumber,tGoodsPrice,mapId);
  		 
  		
  	  	
  	// var url=encodeURI(encodeURI("getprofit_warehouse.action?warehouseid="+tWarehouseId + "&goodsid="+tGoodsId + "&number="+tGoodsNumber));
  	 
  	  	
  		if(!isInteger(tGoodsNumber)){
			//alert("数量 只能输入整数和不能为空!");
			document.getElementById("tGoodsNumber"+mapId).value = 1;
			document.getElementById("tGoodsNumber"+mapId).focus();
			//return;
	  	}
	  	if(tGoodsNumber<=0){
	  		//alert("数量 不能少于1,确认后输入");
	  		document.getElementById("tGoodsNumber"+mapId).value = 1;
			document.getElementById("tGoodsNumber"+mapId).focus();
			
		 }
		
	  	if(tGoodsPrice==""){
	  		//alert("单价 只能输入数字和不能为空!");
	  		document.getElementById("tGoodsPrice"+mapId).value = 0.0;
	  		document.getElementById("tGoodsPrice"+mapId).focus();
	  		//return;
		}
		
		//alert(price);
  	  	if(isNaN(tGoodsPrice)){
			//alert("单价 只能输入数字和不能为空!");
			document.getElementById("tGoodsPrice"+mapId).value = 0.0;
	  		document.getElementById("tGoodsPrice"+mapId).focus();
			//return;
  	  	}
  		
  		var goodsinfo = tWarehouseId + ","
  		+ tWarehouseName + ","
  		+ tGoodsId + ","
  		+ tGoodsName + ","
  		+ tGoodsNumber + ","
  		+ tGoodsUnit + ","
  		+ tGoodsPrice + ","
  		+ tRemark ;
  		//alert(goodsinfo);
  		receiptMap.remove(mapId);
  		receiptMap.put(mapId,goodsinfo);

  		changeTotalInfo();
  		
  		
  		
		
		//alert(mapId + "," + goodsNumber.value + "," + currentGoodsNumber);
  	 }

  	function changeTotalInfo(){
  		shipprice = new Number(document.getElementById("shipprice_receiptlist").value);
  	  	var totalvalue = 0;
  	  	var goodstotalnumber = 0;
  		for(i=0;i<receiptMap.elements.length;i++){
			var mapKey = receiptMap.elements[i].key;
			var goodsNumber = document.getElementById("tGoodsNumber"+mapKey).value;
			var goodsPrice = document.getElementById("tGoodsPrice"+mapKey).value;
			totalvalue += goodsNumber*goodsPrice;
			goodstotalnumber += Number(goodsNumber);
		}//*/
		document.getElementById("goodsnumber").innerHTML = goodstotalnumber;
		shipprice = new Number(document.getElementById("shipprice_receiptlist").value);
		total = totalvalue;
		number = goodstotalnumber;
		document.getElementById("totalDisply").innerHTML = (totalvalue+shipprice) + " <font color='red'>(包含邮费:" + shipprice + ")<font>";
  	 }

  	
	function enterCustomerid(){
  		
  		var customerid = document.getElementById('customerid_receiptlist').value;
  		getLastSalesDateByCustomerid(customerid);
  	}

  	function isInteger(str) {
  		var regu=/^[-]{0,1}[0-9]{1,}$/;
		return regu.test(str);
	} 

  

  	$("#searchStr").die().live("keydown",function(event){       
          if(event.keyCode==13){      
        	//alert("OK" + evt.keyCode);
  			javascript:openUrlForDialog('insertreceiptinfo_warehouse.action?searchStr='+$('#searchStr').attr('value'));
  			return ;   
         }       
  	}); 
  </script>
  
  <script type="text/javascript">

  var goodsreserve = 0;

  	function choseGoods(goodsid,goodsname,goodsunit){

  		//,号异常处理
  		goodsname = goodsname.replace(","," ");
  		goodsunit = goodsunit.replace(","," ");

  		
  		document.getElementById("goodsiddisply").innerHTML = goodsid;
  		document.getElementById("goodsnamedisply").innerHTML = goodsname;
  		document.getElementById("goodsunitdisply").innerHTML = goodsunit;

  		document.getElementById("goodsid").value = goodsid;
  		document.getElementById("goodsname").value = goodsname;
  		document.getElementById("goodsunit").value = goodsunit;
  		
  		getGoodsSellInfo(goodsid);
  		
  		//insertGoods();
  		//getGoodsSellInfo(goodsid);
		//alert(goodsname);
		//window.returnValue=goodsinfo;
		//window.parent.insertGoods(goodsid,goodsname);
		//window.close();
	}

  
  	function insertGoods(){
  	  	var goodsinfo = "";

		var warehouse = document.getElementById("warehouse").value;

		if(warehouse == ""){
			alert("还没选择产品");
			return;
		}
		var index = warehouse.indexOf(",");
		var warehouseid = warehouse.substring(0,index);
		
		
		//alert(document.getElementById("number").value);
		
		document.getElementById("number").value = document.getElementById("number").value.trim();
		document.getElementById("price").value = document.getElementById("price").value.trim();
		
		
		var number = document.getElementById("number").value.trim();
		var price = document.getElementById("price").value.trim();
		var remark = document.getElementById("remark").value.trim();

		
		if(!isInteger(number)){
			alert("数量只能输入整数和不能为空!");
			document.getElementById("number").focus();
			return;
	  	}

	  	if(price==""){
	  		alert("单价只能输入数字和不能为空!");
	  		document.getElementById("price").focus();
	  		return;
		}
		
		//alert(price);
  	  	if(isNaN(price)){
			alert("单价只能输入数字和不能为空!");
			document.getElementById("price").focus();
			return;
  	  	}
		var goodsid = document.getElementById("goodsid").value;
  	  //	getGoodsNumber(warehouseid,goodsid);

  	  //	if(goodsreserve <number){
		//	alert("库存不足");
	//		return;
  	//  	 }
  	  	goodsinfo += document.getElementById("warehouse").value + ",";
  	  	//alert(document.getElementById("warehouse").value);
	  	  	  	
  		goodsinfo += goodsid + ",";
  		goodsinfo += document.getElementById("goodsname").value + ",";
  		goodsinfo +=  number + ",";
  		goodsinfo +=  document.getElementById("goodsunit").value + ",";
  		goodsinfo +=  price + ",";
  		goodsinfo +=  remark + " ";
  		
		
		insertGoodsForTable(goodsinfo);
		$("#dialog").dialog('close');
		
  	}

  	

  

  	function getGoodsSellInfo(goodsid){

  		$.getJSON("getgoodssellinfo_warehouse.action?goodsid=" + goodsid, function(data){ 
			if(data != null){
				document.getElementById('warehousedisply').innerHTML = data.warehouseinfo;
				document.getElementById('number').value = data.lastSellNumber;
		     	document.getElementById('price').value = data.lastSellPrice;
		     	insertGoods();
	  		}
		});

  		
  	}

  	
  	function isInteger(str) {
  		var regu=/^[-]{0,1}[0-9]{1,}$/;
		return regu.test(str);
	} 
  	/**  
  	*删除左右两端的空格  
  	*/  
  	String.prototype.trim=function(){      
  	    return this.replace(/(^\s*)|(\s*$)/g, '');   
  	} 

  	
  </script>
</html>
